package com.hn.project.rqinspect.service.impl;

import com.hn.common.utils.sql.SqlUtil;
import com.hn.project.rqinspect.domain.database.TaskUserGroup;
import com.hn.project.rqinspect.domain.database.UserGroup;
import com.hn.project.rqinspect.mapper.TaskUserGroupMapper;
import com.hn.project.rqinspect.mapper.UserGroupMapper;
import com.hn.project.rqinspect.service.UserGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserGroupServiceImpl implements UserGroupService {

    @Autowired
    private UserGroupMapper userGroupMapper;

    @Autowired
    private TaskUserGroupMapper taskUserGroupMapper;

    @Override
    public List<Integer> listGroupIdsByUserId(Integer userId) {
        UserGroup userGroup = new UserGroup();
        userGroup.setUserId(userId);
        List<Integer> groupIds = new ArrayList<>();
        List<UserGroup> userGroups = userGroupMapper.selectByExample(SqlUtil.newExample(userGroup));
        if (userGroups != null && !userGroups.isEmpty()) {
            for (UserGroup group : userGroups) {
                groupIds.add(group.getGroupId());
            }
        }
        return groupIds;
    }

    @Override
    public List<Integer> listTaskIdsByBranchIds(List<Integer> branchIds) {
        return taskUserGroupMapper.listTaskIdsByBranchIds(branchIds);
    }
}
